package com.yanqu.road.server.cmd.activity.chinesechess;

import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.pb.activity.ChineseChessProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.C2_CHINESECHESS_ACTIVITY_GAME_ENTER, desc = "")
public class CrossChineseChessGaneEnterCmd extends CrossCommand {

    private int activityId;
    private int conditionType;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ChineseChessProto.CrossChineseChessGetRankReqMsg reqMsg = ChineseChessProto.CrossChineseChessGetRankReqMsg.parseFrom(packet.getBytes());
        userId = packet.getPlayerId();
        activityId = reqMsg.getActivityId();
        conditionType = reqMsg.getConditionType();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        CrossActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityNewRankListModel(activityId, conditionType);
        int rank = -1;
        if (rankListModel != null) {
            rank = rankListModel.getMyRank(userId, serverId);
        }
        ChineseChessProto.CrossChineseChessGetRankRespMsg.Builder msg = ChineseChessProto.CrossChineseChessGetRankRespMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setRank(rank);
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_CROSS_CHINESECHESS_RANK_ENTER, msg);
        MessageHelper.sendPacket(serverId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
